mapSNPsToContigs <- function(contig.dataframe,contig.map,cDNA.name){
	#this function extracts snps from individual sequence captured contigs
	#and maps them onto layout corresponding to the structure of 
	#the join.contigs function
	#
	#contig.dataframe is produced by readNewblerMapper
	#contig.map is produced by join.contigs
	#
	tmp.snp.out <- list()
	for(i in 1:length(contig.map[[cDNA.name]]$sc.contig)){
		gctg <- contig.map[[cDNA.name]]$sc.contig[i]
	
		tmp.snp.in <- contig.dataframe[grep(gctg,contig.dataframe$ref.accno),]
	
		#jump to next i if no snps
		if(dim(tmp.snp.in)[1]==0) next
	
		tmp.concat.end <- c(0,contig.map[[cDNA.name]]$concat.end)
		tmp.snp.out[[gctg]] <- tmp.snp.in
		tmp.snp.out[[gctg]][,c('old.start','old.end')] <- tmp.snp.in[,c('start.pos','end.pos')]
		#change start and ends relative to matched contig, and reverse comp if needed
		if(contig.map[[cDNA.name]]$direction[i]=="forward"){
			tmp.snp.out[[gctg]]$start.pos <- tmp.concat.end[i] + tmp.snp.in$start.pos
			tmp.snp.out[[gctg]]$end.pos <- tmp.concat.end[i] + tmp.snp.in$end.pos
		
			}
		if(contig.map[[cDNA.name]]$direction[i]=="reverse"){
			#cat('reversing \n')
			tmp.snp.out[[gctg]]$start.pos <- tmp.concat.end[i] + contig.map[[cDNA.name]]$length[i] - tmp.snp.in$start.pos + 1
		tmp.snp.out[[gctg]]$end.pos <- tmp.concat.end[i] + contig.map[[cDNA.name]]$length[i] - tmp.snp.in$end.pos + 1
			tmp.snp.out[[gctg]]$ref.nucl[tmp.snp.in$ref.nucl!="-"] <- 
				sapply(tmp.snp.in$ref.nucl[tmp.snp.in$ref.nucl!="-"],strComp)
			tmp.snp.out[[gctg]]$var.nucl[tmp.snp.in$var.nucl!="-"] <- 
				sapply(tmp.snp.in$var.nucl[tmp.snp.in$var.nucl!="-"],strComp)

			}
		if(contig.map[[cDNA.name]]$direction[i] %in% c("forward","reverse") == FALSE){
			warning('neither forward nor reverse for', gctg, "in", names(contig.map)[cDNA.name])
			}
		#output is a list of dataframes, one per sequence captured contig
		}
 
 	#tidy up list into a single dataframe
	 if(length(tmp.snp.out)>0){
 		tmp.snp.df <- tmp.snp.out[[1]]
 		if(length(tmp.snp.out)>1){
 			for(i in 2:length(tmp.snp.out)){
 				tmp.snp.df <- rbind(tmp.snp.df,tmp.snp.out[[i]])
 				}
 		
 			}
 		}
	if(length(tmp.snp.out)==0) return(0) #if there's no snps anywhere
	tmp.snp.df[order(tmp.snp.df$start.pos),]
	}

